<?php

namespace Alipay\AlipayFund\Request;

use Alipay\AlipayFund\Info\Parties;
use Alipay\AlipayFund\Info\PayeeList;
use Alipay\AlipayFund\Response\AlipayFundBatchCreateResponse;
use Alipay\Common\RequestBase;

class AlipayFundBatchCreateRequest extends RequestBase
{
    protected $method = 'alipay.fund.batch.create';

    protected $response = AlipayFundBatchCreateResponse::class;

    /**
     * @var Parties
     */
    private $parties;

    /**
     * @var PayeeList
     */
    private $payeeList;

    /**
     * 商户端批次的唯一订单号
     * @var string
     */
    private $outBatchNo;

    /**
     * 批量付款的标题
     * @var string
     */
    private $orderTitle;

    /**
     * 业务备注
     * @var string
     */
    private $remark;

    /**
     * 通用回传参数
     * @var string
     */
    private $callBackParams;

    /**
     * 批次总金额
     * @var string
     */
    private $totalAmount;

    /**
     * 批次总笔数
     * @var string
     */
    private $totalCount;

    /**
     *绝对超时时间，格式为yyyy-MM-dd HH:mm。
     * @var
     */
    private $expireTime;

    /**
     * 生成请求参数
     * @return array
     * @author xis
     */
    public function generate(): array
    {
        $content = [
            'out_batch_no' => $this->outBatchNo,
            'total_trans_amount' => $this->totalAmount,
            'total_count' => $this->totalCount,
            'product_code' => 'BATCH_API_TO_ACC',
            'biz_scene' => 'MESSAGE_BATCH_PAY',
            'order_title' => $this->orderTitle,
            'payer_info' => $this->parties->generate(),
            'trans_order_list' => $this->payeeList->generate()
        ];
        if ($this->callBackParams) {
            $content['passback_params'] = $this->callBackParams;
        }

        if ($this->remark) {
            $content['remark'] = $this->remark;
        }

        if ($this->expireTime) {
            $content['time_expire'] = $this->expireTime;
        }
        return $content;
    }

    /**
     * @param Parties $parties
     * @return $this
     * @author xis
     */
    public function setParties(Parties $parties): self
    {
        $this->parties = $parties;
        return $this;
    }

    /**
     * @param PayeeList $payeeList
     * @return $this
     * @author xis
     */
    public function setPayeeList(PayeeList $payeeList): self
    {
        $this->payeeList = $payeeList;
        $this->totalCount = $this->payeeList->getTotalCount();
        $this->totalAmount = $this->payeeList->getTotalAmount();
        return $this;
    }

    /**
     * @param string $outBatchNo
     * @return $this
     * @author xis
     */
    public function setOutBatchNo(string $outBatchNo): self
    {
        $this->outBatchNo = $outBatchNo;
        return $this;
    }

    /**
     * @param string $orderTitle
     * @return $this
     * @author xis
     */
    public function setOrderTitle(string $orderTitle): self
    {
        $this->orderTitle = $orderTitle;
        return $this;
    }

    /**
     * @param $remark
     * @return $this
     * @author xis
     */
    public function setRemark($remark): self
    {
        $this->remark = $remark;
        return $this;
    }

    /**
     * @param $callBackParams
     * @return $this
     * @author xis
     */
    public function setCallBackParams($callBackParams): self
    {
        $this->callBackParams = $callBackParams;
        return $this;
    }

    /**
     * @param mixed $expireTime
     */
    public function setExpireTime($expireTime): self
    {
        $this->expireTime = $expireTime;
        return $this;
    }


}